package com.aletto.general_store.presenters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.aletto.general_store.R;
import com.aletto.general_store.data.DataRepository;
import com.sisyphus.spinach.core.INetTask;
import com.sisyphus.spinach.network.presenters.NetSingleTask;
import com.sisyphus.spinach.network.views.ToastView;
import com.sisyphus.spinach.ui.configs.impl.DefaultTemplate;

public class FavoritesTemplate extends DefaultTemplate<Object> implements View.OnClickListener {

    private final String id;
    private final TextView button_favorites;

    public FavoritesTemplate(ViewGroup parent, String id) {
        super(parent);
        this.id = id;
        button_favorites = parent.findViewById(R.id.button_favorites);
    }

    @Override
    public void onClick(View v) {
        // v.setSelected(!v.isSelected());

        INetTask.Presenter<Object, INetTask.View<Object>> presenter = presenter();
        presenter.bind(view());
        presenter.execute();
    }

    @Override
    public INetTask.View<Object> view() {
        return new ToastView<>(mParent.getContext());
    }

    @Override
    public INetTask.Presenter<Object, INetTask.View<Object>> presenter() {

        return new NetSingleTask<>(DataRepository.getInstance().favoritesGoods(id, !button_favorites.isSelected()));
    }


}
